import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/message/message_config.dart';
import 'package:ls_work/model/net_time_model.dart';

import '../../net/response/patrol/patrol_check_dats.dart';
import '../../net/response/patrol/patrol_list_data.dart';

class PatrolListViewModel
    extends BaseListViewModel<GuardTaskPointExecuteBeanList> {
  PatrolListViewModel(BuildContext context, this.task) : super(context);
  final GuardTaskExecuteBeanList task;
  var isFirst = true;

  var timeModel = NetTimeModel();

  @override
  Future<List<GuardTaskPointExecuteBeanList>> requestListData() async {
    isFirst = false;
    return await Future(() => (task.taskList??[]).map((e) => GuardTaskPointExecuteBeanList.fromJson(e)).toList());
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  @override
  Future<void> requestRefresh({bool showAni = true}) {
    if (!isFirst) {
      sendMessage(SendMessageEvent(MessageConfig.REFRESH_PATROL));
    }
    return super.requestRefresh(showAni: showAni);
  }

  Future<DateTime?> getNetTime() async {
   try{
     return await timeModel.nowTime();
   }catch(e){
     return null;
   }
  }
}
